package kr.hkit.powerjava.chapter22.work2.dao;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

import kr.hkit.powerjava.chapter22.work2.vo.Department;
import kr.hkit.powerjava.chapter22.work2.vo.Student;

public class DepartmentManagerImpl implements ItemDaointerface<Department> {
	private ArrayList<Department> arList;
	
	public DepartmentManagerImpl(ArrayList<Department> arList) {
		this.arList = arList;
	}

	@Override
	public void addItem(Department Item) {
		arList.add(Item);

	}

	@Override
	public void delItem(Department Item) {
		arList.remove(Item);

	}

	@Override
	public void updateItem(Department Item) {
		if (searchItem(Item)){
			arList.set(arList.indexOf(Item),Item);
			}else{
				System.out.println("수정실패");
			}
			
		}

	

	@Override
	public boolean searchItem(Department Item) {
		// TODO Auto-generated method stub
		return arList.contains(Item);
	}

	@Override
	public void prnItems() {
		prnHeader();
		for(Department s : arList){
			System.out.println(s);
		}
		System.out.println();
	}

	private void prnHeader() {
		String dm= String.format("%s\t%s\t%s\t",
				"번호", "이름", "층수");
		System.out.println(dm);
		System.out.println("===================================");
		
	}

	@Override
	public void prnItems(Comparator<Department> comp) {
		Collections.sort(arList,comp);
		prnItems();

	}

}
